import pygame
from pygame.locals import *
from sys import exit
from PictureClass import *
from Picture import *

'''Class that runs one window of one single-touch viewer of pictures'''
SCREEN_SIZE = (800, 600)

pygame.init()
pygame.display.set_caption("Viewer of Photos")

screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32)  
turtle = Picture("Pictures/turtle.jpg", (110,110))
background = pygame.image.load("Pictures/black-background.jpg").convert()

fullScreen = False
insideRect = False

while True:
    screen.fill((255,255,255))
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
    
    if event.type == MOUSEBUTTONDOWN:
        x1, y1 = pygame.mouse.get_pos()
        deltaX, deltaY = PictureClass().deltaOfPicture(turtle, x1, y1)
        if turtle.getRect().collidepoint(x1,y1):
            insideRect = True
    
    if insideRect:
        if event.type == MOUSEMOTION:
            x2, y2 = pygame.mouse.get_pos()
            if x1 != x2 and y1 != y2:
                turtle.setTopLeft(((x2 - deltaX), (y2 - deltaY)))  

        if event.type == MOUSEBUTTONUP:
            insideRect = False    
            x2, y2 = pygame.mouse.get_pos()
            if x1 != x2 and y1 != y2:
                turtle.setTopLeft(((x2 - deltaX), (y2 - deltaY)))
    
    screen.blit(background, (0, 0))
    fullScreen = PictureClass().fullScreen(SCREEN_SIZE, event, fullScreen)
    screen.blit(turtle.getImage(), turtle.getTopLeft())
    pygame.display.update()